package org.ko.controller;

import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import org.ko.domain.${entityName?cap_first};
import org.ko.service.I${entityName?cap_first}Service;
import org.ko.util.Pageable;
import org.ko.util.Result;


/**
 * ${comment!''}
 * @ByTheWay 
 *  ${date}
 */
@Controller
@RequestMapping("/${entityName?lower_case}/")
public class ${entityName?cap_first}Controller {
	
	private static final Logger logger = LoggerFactory.getLogger(${entityName?cap_first}Controller.class);

	@Autowired
	private I${entityName?cap_first}Service ${entityName?uncap_first}Service;
	
	@RequestMapping(method=RequestMethod.POST,value="update")
	public @ResponseBody Object update(${entityName?cap_first} e) throws Exception {		
		logger.debug("Received request to edit ${entityName?cap_first} id : "+e);				
 		${entityName?uncap_first}Service.update(e);
 		return new Result();
	}
	
	@RequestMapping(method=RequestMethod.POST,value="add") 
	public @ResponseBody Object save(@ModelAttribute ${entityName?cap_first} e) throws Exception {
		logger.debug("Received postback on ${entityName?cap_first} "+e);		
		${entityName?uncap_first}Service.save(e);
		return new Result();
		
	}
	@RequestMapping(method=RequestMethod.POST,value="delete") 
	public @ResponseBody Object delete(Long ids[]) {
		logger.debug("delete ${entityName?cap_first} by id "+Arrays.toString(ids));		
		${entityName?uncap_first}Service.delete(ids);
		return new Result();
		
	}
	
	@RequestMapping(value="findAll")
	public @ResponseBody Object findAll(Pageable p) {
		logger.debug("Received request to list");
		return ${entityName?uncap_first}Service.findAll(p);		
	}

}
